package tech.aistar.controller.noteshow;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import tech.aistar.entity.authordis.Notes;
import tech.aistar.service.noteshow.INoteShowService;
import tech.aistar.vo.noteshow.NotesShowVo;

import java.util.Iterator;
import java.util.List;
import java.util.Map;


/**本类为游记首页显示
 * Created by Dell on 2019/10/1.
 */
@Controller
public class NoteShowController {
    @Autowired
    private INoteShowService noteShowService;


    @RequestMapping("/note")
    public String notesPage(){

        return "traveler_show/travelnotes_index";
    }
    /**
     * @Description:分页显示游记内容
     * @param:
     * @author XiaoDi
     * @date 2019/10/2 13:39
     */
    @RequestMapping("/note_index")
    public String notesShow(Model model, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "8") Integer pageSize){
        Map<String,Object> map = noteShowService.getNoteAll(Integer.valueOf(pageNum),Integer.valueOf(pageSize));



//        PageInfo<NotesShowVo> pageInfo = noteShowService.getNotesAll(Integer.valueOf(pageNum),Integer.valueOf(pageSize));

//        System.out.println(pageInfo.getPages());

        //分页的集合

        PageInfo<Notes> notesPageInfo = (PageInfo<Notes>) map.get("notesPageInfo");

        List<NotesShowVo> notesShowVos = (List<NotesShowVo>) map.get("notesShowVos");

        model.addAttribute("notesPageInfo",notesPageInfo);

        model.addAttribute("notesShowVos",notesShowVos);

        return "traveler_show/travelnotes_data";
    }

    /**
     * @Description:游记内容查询
     * @param:
     * @author XiaoDi
     * @date 2019/10/2 15:51
     */
    @RequestMapping("/find")
    public String findNotePalce(@RequestParam(defaultValue = "")String title,Model model, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "8") Integer pageSize){

        Map<String,Object> map = noteShowService.getNotesAll(title,Integer.valueOf(pageNum),Integer.valueOf(pageSize));

        PageInfo<Notes> notesPageInfo = (PageInfo<Notes>) map.get("notesPageInfo");

        List<NotesShowVo> notesShowVos = (List<NotesShowVo>) map.get("notesShowVos");

        model.addAttribute("notesPageInfo",notesPageInfo);

        model.addAttribute("notesShowVos",notesShowVos);

        model.addAttribute("title",title);

        return "traveler_show/travelnotes_data";
    }
}
